package com.hospital.controller;


import com.hospital.domain.DTO.LoginDTO;
import com.hospital.domain.DTO.SignupDTO;
import com.hospital.domain.pojo.User;
import com.hospital.domain.utils.Result;
import com.hospital.domain.utils.UserContext;
import com.hospital.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Tag(name = "用户接口", description = "无")
public class UserController {

    @Autowired
    private UserService userService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    public Result<User> login(@RequestBody LoginDTO login){
        return userService.login(login.getAccount(), login.getPw());
    }

    @Operation(summary = "注册")
    @PostMapping("/signup")
    public Result<String> signup(@RequestBody SignupDTO signup){
        return userService.signup(signup.getAccount(), signup.getPw(), signup.getRole(), signup.getState(), signup.getId());
    }

    @Operation(summary = "查看用户信息")
    @GetMapping("/info")
    public User getUser(){
        User user = userService.lambdaQuery().eq(User::getUId, UserContext.getUser()).one();
        return user;
    }

    @Operation(summary = "删除用户")
    @DeleteMapping("/delete/{userId}")
    public Result<String> removeUser(@PathVariable("userId") Integer userId){
        return userService.removeUser(userId);
    }

}
